package com.cirnoworks.uhs.client;

	import java.net.DatagramPacket;
	import java.net.DatagramSocket;
	import java.net.InetAddress;
	import java.nio.ByteBuffer;
	import java.util.Random;
	
	public class SenderTest {
	
		public static void main(String[] args) {
			try {
				DatagramSocket[] sockets = new DatagramSocket[5];
				for (int i = 0; i < 5; i++) {
					sockets[i] = new DatagramSocket(13000 + i);
				}
				Random rand = new Random();
				byte[] buf = new byte[65536];
				ByteBuffer buffer = ByteBuffer.wrap(buf);
				DatagramPacket packet = new DatagramPacket(buf, 8);
				packet.setAddress(InetAddress.getByName("localhost"));
				packet.setPort(2499);
				while (true) {
					int id = rand.nextInt(5);
					DatagramSocket socket = sockets[id];
					long value = rand.nextLong();
					buffer.clear();
					buffer.putLong(value);
					buffer.flip();
					packet.setLength(buffer.remaining());
					socket.send(packet);
					packet.setLength(65536);
					buffer.clear();
					socket.receive(packet);
					System.out.println(buffer.getLong() - value);
				}
			} catch (Exception e) {
			}
		}
	}
